﻿using HtmlAgilityPack;
using Newtonsoft.Json.Linq;
using QccAliSlider;
using Serilog;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace EnterpriseInformation.Common
{

    public class HttpUtil
    {
        HttpHelper httpHelper;
        RegexClass regexClass;
        UserHelper userHelper;
 
        
        public string Unique { get; set; }

        public string CompanyName { get; set; }

        public string CompanyUrl { get; set; }
         

        public string BaseUrl
        {
            get
            {
                return "https://www.qcc.com";
            }
            set {; }
        }


        public HttpUtil(UserHelper userHelperIn = null)
        {
            if (userHelperIn == null)
            {
                int index = CommonClass.GetRandom(0, BackService.userHelperList.Count);

                UserHelper userHelper1 = BackService.userHelperList[index];

                this.userHelper = userHelper1;
            }
            else
            {
                this.userHelper = userHelperIn;
            }
            
            
            string cookieStr = userHelper.MyCookie;

            httpHelper = new HttpHelper(BaseUrl, BaseUrl);

            if (!string.IsNullOrEmpty(cookieStr))
            {
                AttachCookie(cookieStr);
            }

            regexClass = new RegexClass();


            string logTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss} [" + $"{userHelper.UserName}" +
              "] [{Level:u3}] {Message:lj}{NewLine}{Exception}";

            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Information()
                .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Warning)
                .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                .MinimumLevel.Override("System", LogEventLevel.Warning)
                .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Warning)
                .Enrich.FromLogContext()
                .WriteTo.Console(outputTemplate: logTemplate).WriteTo.RollingFile("logs/login.txt", outputTemplate: logTemplate)
                .CreateLogger();
        }



        /// <summary>
        /// 绑定Cookie
        /// </summary>
        /// <param name="cookieStr"></param>
        public void AttachCookie(string cookieStr)
        {

            string[] cookieArray = cookieStr.Split(';');

            for (int i = 0; i < cookieArray.Length; i++)
            {
                string[] cookieItem = cookieArray[i].Split('=', 2);

                CommonClass.AddCookie(httpHelper.cookieContainer, cookieItem[0].Trim(), cookieItem[1].Trim(), BaseUrl);
            }


        }

        public ResultModel RetryVerify()
        {
            ResultModel resultModel = new ResultModel();

            try
            {

                ResultModel resultModelSlide = GetSlider();

                if (!resultModelSlide.Passed)
                {
                    resultModel = resultModelSlide;
                    return resultModel;
                }


                JObject slider = JObject.Parse(resultModelSlide.Html);

                string url = BaseUrl + "/index_verifyAction";
                JObject param = new JObject();
                param.Add(new JProperty("type", "companyview"));

                foreach (var paramItem in slider.Properties())
                {
                    string val = paramItem.Name.Replace("_one", "");
                    if (val == "token" || val == "sig" || val == "csessionid" || val == "type" )
                    {
                        param.Add(new JProperty(val, paramItem.Value.ToString()));
                    }
                    else if (val == "scene")
                    {
                        param.Add(new JProperty(val, "register"));
                    }
                }

                List<string> paramList = new List<string>();

                foreach (var paramItem in param.Properties())
                {
                    paramList.Add(paramItem.Name + "=" + CommonClass.UrlEncode(paramItem.Value.ToString()));
                }

                int retry_times = 0;
                Log.Logger.Information("index_verifyAction正在登录中......" + paramList.ToString());

            retry:

                Tuple<string, string> httpLoginResult =
                    httpHelper.HttpPostForm(url, string.Join("&", paramList.ToArray()));


                if (httpLoginResult == null)
                {
                    retry_times++;
                    //if (retry_times < 10)
                    //{
                    //    System.Threading.Thread.Sleep(1000);
                    //    goto retry;
                    //}

                    resultModel.Passed = false;
                    resultModel.Message = $"index_verifyAction登录失败！";
                    Log.Logger.Error(resultModel.Message);
                    return resultModel;
                }

                JObject loginResult = JObject.Parse(httpLoginResult.Item2);

                resultModel.Passed = true;
                resultModel.Html = httpLoginResult.Item2;
                resultModel.Message = "恭喜登录成功!";

            }
            catch (Exception ex)
            {
                resultModel.Message = ex.ToString();

                Log.Logger.Error(resultModel.Message + "index_verifyAction");

            }

            return resultModel;

        }
        public static long ConvertDateTimeInt(System.DateTime time)
        {
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
            long t = (time.Ticks - startTime.Ticks) / 10000;            //除10000调整为13位
            return t;
        }
        public static string ConvertToUtf8(string text)
        {
            //byte[] utf8 = Encoding.UTF8.GetBytes(text);
            //string result = Encoding.UTF8.GetString(utf8);
            //return result;

            return System.Web.HttpUtility.UrlEncode(text).Replace("+", "%20");


        }
        public static string RegexString(string input, string pattern, string groupName)
        {
            try
            {

                foreach (Match match in Regex.Matches(input, pattern))
                {

                    return match.Groups[groupName].Value.ToString();

                }

            }
            catch (Exception)
            {


            }


            return "";

        }
        private static ResultModel SliderHelper()
        {
            ResultModel resultModel = new ResultModel();

            try
            {

                string userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36";
                string qnyxt = "QNYX:" + ConvertDateTimeInt(DateTime.Now).ToString();
                string url = "https://cfus.aliyun.com/nocaptcha/analyze.jsonp?a=QNYX&t=" + ConvertToUtf8(qnyxt) + "&t=&n=137%238sE9hE9oU4CKXdwHWcAWMcHqInqNQ7BLW1efK3BPs31CBpdZ39ZYNRvf%2FmIV4pCIP2cL3uSiyoS2ZIwBE11cfXUI71xVmlx0b1wKngNngs9SrixUmNIDq2OifPFEwM8xbD60Y29nrE3Igbz7NXCVYuiPomj1jbu1GNWmkcLuAKaEaM%2BmtBtDnrU2wM7SwuxGVDL1qPL%2FliNXGUgPEKscg8alRDSgDG8AaLOLLES9KQh5n1T2EkOdelF3KAW%2FRJ3A5eOvtlKUZch6ocDfUf8jATvQ8%2FSzUN3gmZIgdxsrR3lOj%2BsAlbx%2BMkBrOG5d5VFVEUqbFEhKXZ5BFr7znOQHHQW%2BxDhhCqNKxoeMKsrV1tViyFzwAMqA1J4XGNvFBvDIthJOysTSkzpr3qqS0QLP7RrHEGwhX%2BHQ9KI5RGEtsuouR13gx1n%2FbW9KCE61xDTo0I4gGnzGRpoWbCJfBX1f7fbgllgETXRl%2F0aJi9ptDZcMkOz0aHLzcoXlZRoNZktI%2BnD2s0TV3jEfrAQXVh1DyFXQBMUKNNpi97B3OQZSaUoEFUhC5nW9yaDXlSXGapwTVHhUJHVJJIVEDLVsDTdBVxhu9EZ24Q2Ueb6MwMw3aTKZ%2BsxJqS7D2sA0Jh5y0qxkObYgFGLVvbE5OPsiOLAhiMqlKmjn9SCnb1x4WsjscUcEKu%2FDBKfUVMwWcAGlP7LjftDNK5h10%2FPXXfhYNripA1ec8JFn%2FNejdCApmc4oA4F0kWzZ6pM6dkuIC2ThGAu2scrmJi972YJXUjZjAhZTOnyxb6%2FW4I4XqHIbexEswICwWu3Bq3VjTOHnwv7QEDeBWgknYDlprYyP22iPQQSvFMqUzD61HaqSjrCcxY37PsIbF92wGqwXUOBonyuKzw4PruWA5DT6PXnaxi5aRRYfS%2BFTVfJPvM5DX6B4%2FIu1lATrk103%2BozfWBdtbFZsxIt128YSrMhMLyOL%2Fgv595zltlNQCffb7SiOX4Ejj9AFJflrQi5S9Wx0sN56zeTZIeoRhyi2pTuc6Dt4zltq%2FbJf5YLdbJdxOh5d9h9%2FwedwJyD4jEEN0BUqX9I6EQyOfU%2BG95R8JTzJV6ev4lgrjrdMVJp1rM%2BMAlTgws0EzY9IQPtQAFnnFfhlQ9rsjyN8SnsMG6WzYfnDc7ms6SkWd%2F5SF8cgbZmYj1ghu0iItjtPjUSgowtF5Jl4b2gWHJg1gQ4ir%2F1aP1lE%2FBhdQEQ5RIVWpA0PWoI8Pjm3r5WvM%2BDWiklxRyo109YyWiUBYIAV9jAlOePAVzh9LtBzQFsD0AJfVUpN%2FcBuCHpXSBMzEmpsbcHE7yssWfxgK%2BgW6bi7I55i76zxYrcESBPHbMxIaocfBABjUCqGK3qYBn%2FjHcjxOMeQejC%2BTe7YSIi5u%2FR7UTakAqCqxbpknkF6Z0pntoamy%2FcK7KvMEIjY6cZ56mgZBfsJmfJxhQy7qDLCR3MM7q%2FF2jm5hsBZ4VMfqofwt%2FEsTKPphDmY9Lm20JUlSm4TnbIQ8qNF%2FvvXVSZxnu12K8%2Bw%2Fx16ak0Ol7hpxsnPCa7iDPv4bXrxDOSyMUhrCz9sZ1ffpzz9r3%2Fz75JyAl7N0jd5f2vyL7qoMAhukmXDjBG1XSQ%2FEylwb3gbQbpVIuAEqHIqFUDmBPm91tg8zRV8giM1RhNjYTUx1lg8p2dWDIXl5%2BB9pX1h1IEi%2BVipYTSoc893pppmexgqK8GppkUc1Aey%2BtiVMSUS1vxRkgrXQofv%2BGDpghhM1IeyamWVYSUS1lL0qod73S6rvDkrEkfm1AEy%2BpP9YTUx1lgippXmQofJ%2BZDppRJc1Iei%2BppVi9juFu7t9%2BVUz3F68ggI4Byg%2BBq7mNnzv2%2Fi3e9mDFrOHBitI%2FayukpLQsoDMsB7a32lhvER%2BAKJEg9GlaRTqhnRRIn5ePskZH5MliTijdMAVb83URIKmNnEXId9JfpITKUL%2B0dkLIwYMSiOA2OBJyR01rLXIuMr3yHCDvKjTYNspvejKX3GePtgiheLY%2FhNQrYnVFCEewe8%2BK77uvfixvJ9uhnuOeYFOaLqtED6op1yCIsK2TE%2BK4tJJHOAjevRzWkaCOJupNHMCsun2%2BcaTjOHj9KkSZcHnb3jYnVSBLpATOgj9HdoAYZwNotzaoKafvkMp%2BEMLhkekBq%2F8an%2B3JtWWG5gIvG%2BAoIJqqlM4Tj1mYcAFsi%2Bz31%2BXRqC%2BGxR5m3oqWYVxnTYkrmePQpdhP7ScsdRVG4rzrlLKd1obxKasTWjotP3Xi%2BMUplbL1lzeKz9RllQi4ha5VhkqNP%3D&p=%7B%22ncSessionID%22%3A%226bee7214ab60%22%2C%22umidToken%22%3A%22T2gAHTfHR5qdgtP6ZXBRBjbuRQnL8mTyrUawu1BGHnSkOnPff554bGXTwyTFxwlI9Hr4iFWjVjg9f6I8XtVS8e86%22%7D&scene=login&asyn=0&lang=cn&v=1028&callback=jsonp_" + ConvertDateTimeInt(DateTime.Now).ToString();

                QccAliSlider.HttpHelper httpHelper = new QccAliSlider.HttpHelper();

                WebHeaderCollection header = new WebHeaderCollection();

                header.Add("Accept-Encoding: gzip, deflate");
                header.Add("Accept-Language: zh-CN,zh;q=0.9");
                header.Add("authority: cf.aliyun.com");



                HttpItem httpItem = new HttpItem()
                {
                    URL = url,
                    Method = "GET",
                    Accept = "*/*;",
                    UserAgent = userAgent,
                    IndicateHost = "cf.aliyun.com",
                    Header = header,
                    Timeout = 10 * 1000,
                    Allowautoredirect = false,
                    Encoding = UTF8Encoding.UTF8,
                    KeepAlive = true
                };


                int retry_times = 0;
                int max_retry_times = 3;


            retry:


                HttpResult httpResult = httpHelper.GetHtml(httpItem);


                switch (httpResult.StatusCode)
                {
                    case System.Net.HttpStatusCode.Forbidden:
                    case System.Net.HttpStatusCode.Found:
                    case System.Net.HttpStatusCode.GatewayTimeout:
                    case System.Net.HttpStatusCode.BadGateway:
                    case System.Net.HttpStatusCode.Moved:
                    case System.Net.HttpStatusCode.ServiceUnavailable:   //503
                    case (System.Net.HttpStatusCode)596:
                    case System.Net.HttpStatusCode.NotFound:
                        resultModel.Message = "正在识别滑块验证码系统繁忙！";
                        return resultModel;
                    case HttpStatusCode.OK:

                        string jsonTxt = httpResult.Html;

                        if (string.IsNullOrEmpty(jsonTxt))
                        {
                            if (retry_times < max_retry_times)
                            {
                                retry_times++;
                                goto retry;

                            }
                            else
                            {
                                resultModel.Message = "正在识别滑块验证码返回数据为空";
                                return resultModel;

                            }

                        }


                        if ((!jsonTxt.StartsWith("{") &&
                            !jsonTxt.EndsWith("}")) && (!jsonTxt.StartsWith("jsonp")))
                        {
                            resultModel.Message = "滑块验证码格式错误";
                            return resultModel;
                        }

                        string content = RegexString(jsonTxt, @"^\w+\((?<g1>[^()]+)\)", "g1");

                        JObject jobj = JObject.Parse(content);

                        if (jobj.Property("result") == null ||
                            string.IsNullOrEmpty(jobj["result"].ToString()))
                        {
                            string message = jobj["result"].ToString();
                            if (message == "timeout")
                            {
                                if (retry_times < max_retry_times)
                                {
                                    retry_times++;
                                    goto retry;

                                }

                            }

                            resultModel.Message = "连接识别滑块验证码服务器失败";
                            return resultModel;

                        }

                        JObject data = (JObject)jobj["result"];
                        JObject jparam = new JObject();
                        jparam.Add(new JProperty("verify_type", "1"));
                        jparam.Add(new JProperty("scene_one", "login"));
                        jparam.Add(new JProperty("keep", "option1"));
                        jparam.Add(new JProperty("token_one", qnyxt));
                        jparam.Add(new JProperty("sig_one", data["value"].ToString()));
                        jparam.Add(new JProperty("csessionid_one", data["csessionid"].ToString()));
                        resultModel.Html = jparam.ToString();

                        resultModel.Passed = true;


                        break;
                    case (System.Net.HttpStatusCode)0:
                    default:
                        if (retry_times < max_retry_times)
                        {
                            retry_times++;
                            goto retry;

                        }
                        else
                        {
                            resultModel.Message = "数据返回空数据";
                            return resultModel;

                        }

                        break;
                }



            }
            catch (Exception ex)
            {

                if (resultModel == null)
                {
                    resultModel = new ResultModel();
                }

                resultModel.Message = ex.ToString();
            }


            return resultModel;

        }

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userHelper"></param>
        /// <returns></returns>
        public ResultModel Login() 
        {
            ResultModel resultModel = new ResultModel();

            try
            {
                ResultModel resultModelSlide = SliderHelper();

                if (!resultModelSlide.Passed)
                {
                    System.Console.WriteLine("获取滑块失败！");
                    resultModelSlide = GetSlider();
                    if (!resultModelSlide.Passed)
                    {
                        resultModel = resultModelSlide;
                        userHelper.MyCookie = "";
                        userHelper.MyStatus = false;
                        return resultModel;
                    }
                }

                JObject slider = JObject.Parse(resultModelSlide.Html);

                slider.Add(new JProperty("phone_prefix", "+86"));
                slider.Add(new JProperty("nameNormal", userHelper.UserName));
                slider.Add(new JProperty("pwdNormal", userHelper.PassWord));

                 
                string url = BaseUrl +  "/user_loginaction"; 
                List<string> param = new List<string>();

                foreach (var paramItem in slider.Properties())
                {
                    param.Add(paramItem.Name + "=" + CommonClass.UrlEncode(paramItem.Value.ToString()));                    
                } 

                int retry_times = 0;
                Log.Logger.Information("正在登录中......");
                
                retry:

                Tuple<string, string> httpLoginResult =
                    httpHelper.HttpPostForm(url, string.Join("&", param.ToArray()));


                if (httpLoginResult == null)
                {
                    retry_times++;
                    //if (retry_times < 10)
                    //{
                    //    System.Threading.Thread.Sleep(1000);
                    //    goto retry;
                    //}

                    resultModel.Passed = false;
                    resultModel.Message = $"登录失败！";
                    Log.Logger.Error(resultModel.Message);
                    return resultModel;
                }

                JObject  loginResult = JObject.Parse(httpLoginResult.Item2);

                if (loginResult.Property("success") != null && Convert.ToBoolean(loginResult["success"].ToString()))
                {
                    resultModel.Passed = true;
                    resultModel.Html = httpLoginResult.Item2; 
                    resultModel.Message = "恭喜登录成功!";

                    userHelper.MyCookie = httpLoginResult.Item1;
                    userHelper.MyStatus = true; 
                    Log.Logger.Information(resultModel.Message);

                }  else {
                    userHelper.MyCookie = "";
                    userHelper.MyStatus = false;

                    if (loginResult.Property("msg") != null &&
                      loginResult["msg"].ToString().Contains("错误"))
                    {
                        resultModel.Retry = false;
                        resultModel.Message = loginResult["msg"].ToString();
                    }


                    //retry_times++;
                    //if (retry_times < 10 && resultModel.Retry)
                    //{
                    //    System.Threading.Thread.Sleep(1000);
                    //    goto retry;
                    //}

                    resultModel.Passed = false;
                    if (string.IsNullOrEmpty(loginResult["msg"].ToString()))
                    {
                        resultModel.Message = $"登录失败！";
                    }                  
                    Log.Logger.Error(resultModel.Message);
                    return resultModel; 

                }

            }
            catch (Exception ex)
            {
                resultModel.Message = ex.ToString();

                Log.Logger.Error(resultModel.Message);

            }

            return resultModel;

        }


        /// <summary>
        /// 滑动滑块验证码
        /// </summary>
        /// <returns></returns>
        public ResultModel GetSlider()
        {

            ResultModel resultModel = new ResultModel();

            try
            {
                //获取验证码参数
                HttpHelper myHttpHelper = new HttpHelper();

                string apiUrl = MyConfig.WebHelperApi;

                List<string> param = new List<string>();

                param.Add("group=ws-group-cailaoban");

                param.Add("action=qcc_slide");

                int retry_times = 0;

                Log.Logger.Information("加载滑块中......");

            retry:

                Tuple<string, string> httpSlideResult =
                    myHttpHelper.HttpPostForm(apiUrl, string.Join("&", param.ToArray()));


                if (httpSlideResult == null || !Convert.ToBoolean(JObject.Parse(httpSlideResult.Item2)["ok"]))
                {
                    //retry_times++;
                    //if (retry_times < 10)
                    //{
                    //    System.Threading.Thread.Sleep(1000);
                    //    goto retry;
                    //}

                    resultModel.Passed = false;
                    resultModel.Message = $"滑块验证失败！";
                    Log.Logger.Error(resultModel.Message);
                    return resultModel;
                }

                JObject slider = JObject.Parse(httpSlideResult.Item2);

                if (slider.Property("data") == null)
                {
                    retry_times++;
                    //if (retry_times < 10)
                    //{
                    //    System.Threading.Thread.Sleep(1000);
                    //    goto retry;
                    //}

                    resultModel.Passed = false;
                    resultModel.Message = $"滑块处理失败！";
                    Log.Logger.Error(resultModel.Message);
                    return resultModel;

                }

                JObject data = (JObject)slider["data"];

                data.Remove("__sekiro_seq__");

                resultModel.Html = data.ToString(); 

                resultModel.Passed = true;

                Log.Logger.Information("滑动滑块成功！");



            }
            catch (Exception ex)
            {
                resultModel.Message = ex.ToString();

                Log.Logger.Error(resultModel.Message);

            }

            return resultModel;

        }

        /// <summary>
        /// 初始化首页获取Cookie
        /// </summary>
        /// <returns></returns>
        public ResultModel InitIndex()
        {
            ResultModel resultModel = new ResultModel();

            try
            {
                string url = BaseUrl;
                Log.Logger.Information($"初始化连接[{url}]......");

                int retry_index = 0;

                retry:

                Tuple<string, string> httpGetResult = httpHelper.HttpGet(url);

                if (httpGetResult == null)
                {
                    retry_index++;
                    if (retry_index < 3)
                    {
                        goto retry;
                    }

                    resultModel.Passed = false;
                    resultModel.Message = $"初始化连接[{url}]失败！";
                    Log.Logger.Error(resultModel.Message);
                    return resultModel;
                }
                 

                resultModel.Passed = true;
                resultModel.Html = httpGetResult.Item2;

                Log.Logger.Information($"初始化连接[{url}]完成!");


            }
            catch (Exception ex)
            {
                resultModel.Message = ex.ToString();
                Log.Logger.Error(resultModel.Message);
            } 
            return resultModel; 
        }
        
        /// <summary>
        /// 获取详细信息
        /// </summary>
        /// <returns></returns>
        public ResultModel HttpGet(string url)
        {
            ResultModel resultModel = new ResultModel();
            try
            {

                httpHelper.httpClient.DefaultRequestHeaders.Referrer = new Uri(url);

                Log.Logger.Information($"正在打开[{url}]......");

                Tuple<string, string> httpGetResult = httpHelper.HttpGet(url);

                if (httpGetResult == null)
                {
                    resultModel.Passed = false;
                    resultModel.Message = $"打开[{url}]失败!";
                    Log.Logger.Error(resultModel.Message);
                }
                else
                {
                    resultModel.Html = httpGetResult.Item2.Replace("企查查", "律格尔").Replace("小查", "律格尔").Replace("\\n", "").Replace("查查图谱", "天眼图谱");
                    resultModel.Passed = true;
                }

            }
            catch (Exception ex)
            {
                resultModel.Passed = false;
                resultModel.Message = ex.ToString();
                Log.Logger.Error(resultModel.Message);
            }

            return resultModel;

        }

        public ResultModel HttpPostForm(List<string> param, string url)
        {

            ResultModel resultModel = new ResultModel();

            try
            {
                JObject slider = new JObject();
                
                int retry_index = 0;

            retry:

                Log.Logger.Information($"正在查询关键字:[{param.ToString()}]......");

                Tuple<string, string> httpResult =
                        httpHelper.HttpPostForm(url, string.Join("&", param.ToArray()));

                if (httpResult == null)
                {
                    retry_index++;
                    if (retry_index < 3)
                    {
                        System.Threading.Thread.Sleep(500);
                        goto retry;
                    }

                    resultModel.Passed = false;
                    resultModel.Message = $"查询关键字:[{param.ToString()}]失败!";
                    Log.Logger.Error(resultModel.Message);
                    return resultModel;
                }

                resultModel.Html = httpResult.Item2;
                resultModel.Passed = true;
                resultModel.Message = $"通过关键字查找到[{ param.ToString() }]";
                Log.Logger.Information(resultModel.Message);
            }
            catch (Exception ex)
            {
                resultModel.Message = ex.ToString();
                Log.Logger.Error(resultModel.Message);
            }

            return resultModel;

        }

        public ResultModel HttpPostJson(string json, string url)
        {

            ResultModel resultModel = new ResultModel();

            try
            {
                JObject slider = new JObject();

                int retry_index = 0;

            retry:

                Log.Logger.Information($"正在查询关键字:[{json}]......");

                Tuple<string, string> httpResult =
                        httpHelper.HttpPostJson(url, json);

                if (httpResult == null)
                {
                    retry_index++;
                    if (retry_index < 3)
                    {
                        System.Threading.Thread.Sleep(500);
                        goto retry;
                    }

                    resultModel.Passed = false;
                    resultModel.Message = $"查询关键字:[{json}]失败!";
                    Log.Logger.Error(resultModel.Message);
                    return resultModel;
                }

                resultModel.Html = httpResult.Item2;
                resultModel.Passed = true;
                resultModel.Message = $"通过关键字查找到[{ json }]";
                Log.Logger.Information(resultModel.Message);
            }
            catch (Exception ex)
            {
                resultModel.Message = ex.ToString();
                Log.Logger.Error(resultModel.Message);
            }

            return resultModel;

        }




    }
}
